﻿@model NewProject.Models.Post
  
<div class="reviewBox" id="@Model.PostID">

  @{

      double AvgStars = 0.0;
      double TotalStars = 0;
      double TotalCounts = 0;

    <div class="reviewForPost">
        
       @foreach (var review in Model.Reviews)
        {
            TotalCounts++;
            TotalStars += review.Rating;
            <label class="singleReview">
                <span>@review.UserName</span>
            
                @for (int i = 0; i < review.Rating; i++)
                {<span id="stars"> ★</span>}
                @if ((User.Identity.Name == Model.UserName) || (User.Identity.Name == review.UserName))
                {
                    @Html.ActionLink("Delete", "DeleteReview", new { id = review.ReviewID })
                }
                <br />
                @if (!String.IsNullOrWhiteSpace(review.ReviewText))
                {
                    <span id="reviewText">@review.ReviewText</span>
                }

            </label>
            AvgStars = TotalStars / TotalCounts;

        }

    </div>
      
      <div class="publicRating">
      
      @for (int i = 0; i < 5; i++)
      {
          

          if ((AvgStars)>i+0.75)
          {
            <img src="~/Images/star-on.png" />

        }
          else if (AvgStars>i+0.25)
        {
            <img src="~/Images/star-half.png"  />
        }
          else
          {
            <img src="~/Images/star-off.png" />
          }
      }
          <br />
          <span>@TotalCounts user(s) voted: @AvgStars</span>
          </div>
         

  }
    </div>



